<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #app{
      width: 200px;
      height: auto;
      flex-wrap: wrap;
      justify-content: space-between;
    }
    .item {
      width: 200px;
      height: 250px;
      background-color: gray;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      align-items: center;
      margin-bottom: 5px;
    }

    .btn {
      width: 80px;
      height: 30px;
    }
    img{
      width: 150px;
      height: 150px;
    }
  </style>
</head>

<body>
  <template id="red">
    <div class="item">
      <img :src="item.img" alt="">
      <span>{{item.name}}</span>
      <span>{{item.dl}}</span>
      <span>{{itd}}</span>
      <button class="btn" @click="texts">立即购买</button>
    </div>
  </template>
  <div id="app">
    <span>{{text}}</span>
    <redmi v-for="(item,index) in list" :item="item" @ev="ev" />
  </div>
  <script src="./js/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
          data() {
            return {
              list: [{
                img: 'd6354c72c3c1119fa59453dd3a64701e.jpg',
                name: 'Note 11 5 G',
                dl: '5000mAh大电量',
                price: 1199
              },{
                img: 'd6354c72c3c1119fa59453dd3a64701e.jpg',
                name: 'Note 12 5 G',
                dl: '5000mAh大电量',
                price: 1199
              }],
              text:''
            }
          },methods:{
            ev(val){
              this.text = val
            }
          },
      components: {
        'redmi': {
          template: '#red',
          computed:{
            itd(){
              return `￥${this.item.price}`
            }
          },
          props:{
            item:{
                type:Object,
                required:true
            }
          },methods: {
            texts(){
              this.$emit('ev', "我是子组件传递过来的值");
            }
          },
        }
      }
    })
  </script>
</body>

</html>